<?php
/////////////////////////////////////////////////////////////////////////////////////		
include "required_code.php"; 

	session_start();
	$ses_user_id =$_SESSION['ses_user_id'];
	$ses_std_id = $_SESSION['ses_std_id'];
	if($ses_user_id <> session_id() or  $ses_std_id ==''){
		echo "Authentication failed";
		echo "<meta http-equiv='refresh' content='2;URL=index.php' />";
		}    
							$query2="SELECT * FROM std_progress WHERE std_id=$ses_std_id";
							$db_result2=db_query($query2);
							$result2=mysql_fetch_array($db_result2);
							//echo $result2['pretest_sts'];
								if($result2['ls_sts']==1){
								echo "Redirecting";
								echo "<meta http-equiv='refresh' content='1;URL=progress.php' />";
							}
							else {
/////////////////////////////////////////////////////////////////////////////////////	
////////////////////////////UPDATE ls_TEST SCORE///////////////////////////////
						$i = 1;		
						for ($i = 1; $i <= 22; $i++){ 
							$query_update_ls_test_score= "INSERT INTO std_ls_ans(std_id,ls_test_item,ls_test_ans) VALUES ('".$ses_std_id."','".$i."','".$_POST['item'][$i]."')";
							//echo $query_update_pretest_score."<br>";
							$db_query_update_ls_test_score=db_query($query_update_ls_test_score);
							
						}
						if($db_query_update_ls_test_score){
								
								///////////////////////UPDATE ls_TEST STATUS (0 -> 1) //////////////////////////			
								$query_update_ls_test_sts= "UPDATE std_progress SET ls_sts='1' WHERE std_id='".$ses_std_id."'";
											//echo $query_update_pretest_score."<br>";
								db_query($query_update_ls_test_sts);

										
								///////////////////////UPDATE ls_TEST STATUS (0 -> 1) //////////////////////////
						}
				
				////////////////////////////UPDATE ls_TEST SCORE///////////////////////////////
						
 
 
 ////////////////////////////LS TEST RESULT///////////////////////////////
							
							//////////////// VISUAL LEARNER CHECK///////////////////
							$query_visual="SELECT * FROM std_ls_ans WHERE std_id='".$ses_std_id."' AND ls_test_item>='1' AND  ls_test_item<='11'";
							$db_result_visual=db_query($query_visual);
							$visual_score=0;
							while($result_visual=mysql_fetch_array($db_result_visual)){
								if($result_visual['ls_test_ans']=='A') $visual_score++;
							}
							//echo $visual_score;
							//////////////// VISUAL LEARNER CHECK///////////////////

							//////////////// KINESTHETIC LEARNER CHECK///////////////////
							$query_kinesthetic="SELECT * FROM std_ls_ans WHERE std_id='".$ses_std_id."' AND ls_test_item>='12' AND  ls_test_item<='22'";
							$db_result_kinesthetic=db_query($query_kinesthetic);
							$kinesthetic_score=0;
							while($result_kinesthetic=mysql_fetch_array($db_result_kinesthetic)){
								if($result_kinesthetic['ls_test_ans']=='A') $kinesthetic_score++;
							}
							//echo $kinesthetic_score;
							//////////////// KINESTHETIC LEARNER CHECK///////////////////
					

							if ($visual_score>$kinesthetic_score OR $visual_score==$kinesthetic_score){
								$std_ls="VSL";
							}
							else{
								$std_ls="KNT";
							}
							$query_insert_ls_sts= "INSERT INTO std_ls_status(std_id,std_ls) VALUES ('".$ses_std_id."','".$std_ls."')";
							//echo $query_update_pretest_score."<br>";
							db_query($query_insert_ls_sts);
								//if($db_query_success) {
									echo "Your test answers have been saved successfully.";
									echo "<meta http-equiv='refresh' content='1;URL=progress.php' />";
								//}							
					
							
			////////////////////////////LS TEST RESULT///////////////////////////////						
						
						
						
/////////////////////////////////////////////////////////////////////////////////////		
		$db_close=db_disconnect($db_open);
		}
/////////////////////////////////////////////////////////////////////////////////////		
?>